﻿using System;
using System.Windows.Forms;
using System.Diagnostics;

namespace ShutdownUtil {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e) {
            //this.Width = label1.Width + 2 * label1.Left;
            this.Width = btnExecute.Left * 2 + btnExecute.Width + btnCancel.Width + btnCancel.Left - btnExecute.Right;
            label1.Left = (this.Width - label1.Width) / 2;
        }

        private void btnExecute_Click(object sender, EventArgs e) {
            int secs = 2 * 60;
            if (rd45s.Checked) secs = 45;
            else if (rd5min.Checked) secs = 5 * 60;
            else if (rd15min.Checked) secs = 15 * 60;
            try {
                if (rdcancel.Checked) {
                    Process.Start("C:/Windows/System32/shutdown.exe", "-a");
                } else {
                    Process.Start("C:/Windows/System32/shutdown.exe", "-s -t " + secs);
                }
                this.Close();
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e) {
            Application.Exit();
        }
    }
}